package bpm.dao.impl.process;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import bpm.domain.process.Node;
import bpm.domain.process.NodeType;
import bpm.domain.process.ProcessDefinition;

/**
 * 
 * @author <a mailto="hwangsyin@gmail.com">King</a>
 *
 */
public class NodeMapper implements RowMapper {

	public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
		Node node = new Node();
		
		node.setProcessDefinition(new ProcessDefinition(rs.getString("procdef_id")));
		node.setId(rs.getString("node_id"));
		node.setName(rs.getString("name"));
		String typeKey = rs.getString("type_key");
		if(typeKey != null && !"".equals(typeKey)) {
			node.setType(NodeType.valueOf(typeKey));
		}
		String taskType = rs.getString("task_type");
		if(taskType != null && !"".equals(taskType)) {
			node.setTaskType(Node.TaskType.valueOf(taskType));
		}
		node.setReference(rs.getString("reference"));
		node.setDescription(rs.getString("description"));
		
		return node;
	}

}
